{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.io as scio\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_mat(path):\n",
    "    \"\"\"\n",
    "    读取mat文件。\n",
    "    :param path:\n",
    "    :param flag:\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    temp = scio.loadmat(path)\n",
    "    return temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walk_dir(path):\n",
    "    \"\"\"\n",
    "    scan dir\n",
    "    :param path: 文件路径\n",
    "    :return: list\n",
    "    \"\"\"\n",
    "    data_path = path + 'EEG_Feature_5Bands/'\n",
    "    label_path = path + 'perclos_labels/'\n",
    "    data_list = []\n",
    "    for item in os.listdir(data_path):\n",
    "        data_list.append(data_path + item)\n",
    "    label_list = []\n",
    "    for item in os.listdir(label_path):\n",
    "        label_list.append(label_path + item)\n",
    "\n",
    "    print(\"路径 {} 扫描完成！\".format(path))\n",
    "    return data_list, label_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "PATH = '/home/zionxie/Documents/completely/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "路径 /home/zionxie/Documents/completely/ 扫描完成！\n"
     ]
    }
   ],
   "source": [
    "file_path = walk_dir(PATH)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(17, 885, 5)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "read_mat(file_path[0][0])['de_LDS'].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
